﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mimoza.AgentLayer
{
    public class ProcessPluginResult : BaseObject
    {
        public ProcessPluginResult(Configuration config)
            : base(config)
        {
        }

        public ProcessPluginResult()
            : base(null)
        {
        }

        public static void Process(Configuration config, Mimoza.PluginLayer.PluginResult result)
        {
            new ProcessPluginResult(config).ProcessResult(result);
        }

        public void ProcessResult(Mimoza.PluginLayer.PluginResult result)
        {
            if (result.NeedToReboot)
            {
                Common.Logger.Log.Info("ProcessPluginResult.ProcessResult prepare to REBOOT.");

                Configuration.Deinit();
                System.Threading.Thread.Sleep(1000); // wait before restart to flash info to disc

                RebootSystem();
            }
        }

        void RebootSystem()
        {
            Common.Logger.Log.Info("ProcessPluginResult.ProcessResult REBOOT SYSTEM...");

            SystemPower.Reboot();
        }
    }
}
